#Presentación Este documento presenta gráficos generados a partir de los datos de COVID-19 en Costa Rica compartidos por el Ministerio de Salud en https://geovision.uned.ac.cr/oges/.
covid_nacional <-
read_delim(
file = "05_24_22_CSV_GENERAL.csv",
delim = ";",
col_select = c("FECHA", "positivos", "fallecidos", "RECUPERADOS", "activos")
)
## Rows: 810 Columns: 5
## -- Column specification --------------------------------------------------------
## Delimiter: ";"
## chr (1): FECHA
## dbl (4): positivos, fallecidos, RECUPERADOS, activos
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
covid_cantonal_positivos <-
read_delim(
file = "05_24_22_CSV_POSITIVOS.csv",
delim = ";",
locale = locale(encoding = "WINDOWS-1252"), # esto es para resolver el problema con las tildes
col_select = c("canton", "24/05/2022")
)
## Rows: 84 Columns: 2
## -- Column specification --------------------------------------------------------
## Delimiter: ";"
## chr (1): canton
## dbl (1): 24/05/2022
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
options(scipen = 7)
# Transformación de datos nacionales de covid-19
covid_nacional <-
covid_nacional %>%
select(fecha = FECHA,
positivos,
fallecidos,
recuperados = RECUPERADOS,
activos) %>%
mutate(fecha = as.Date(fecha, format = "%d/%m/%Y"))
# Transformación de casos positivos de covid-19 por cantón
covid_cantonal_positivos <-
covid_cantonal_positivos %>%
rename(positivos = '24/05/2022')
# Visualización de datos nacionales de covid-19 en formato tabular
covid_nacional %>%
datatable(options = list(
pageLength = 20,
language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json')
))
# ggplot2 - gráfico de línea
covid_nacional %>%
ggplot(aes(x = fecha, y = value, color = variable)) +
ggtitle("Casos acumulados de covid-19 en Costa Rica") +
xlab("Fecha") +
ylab("Casos") +
geom_line(aes(y = positivos, color = "Positivos")) +
geom_line(aes(y = recuperados, color = "Recuperados")) +
geom_line(aes(y = activos, color = "Activos")) +
geom_line(aes(y = fallecidos, color = "Fallecidos")) +
scale_colour_manual(
"",
values = c(
"Positivos" = "blue",
"Recuperados" = "green",
"Activos" = "red",
"Fallecidos" = "black"
)
)
# Visualización de casos positivos de covid-19 por cantón en formato tabular
covid_cantonal_positivos %>%
datatable(options = list(
pageLength = 20,
language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json')
))
ggplot2_barras_identity <-
covid_cantonal_positivos %>%
slice_max(positivos, n = 15) %>% # se seleccionan los 15 cantones con mayor cantidad de casos
ggplot(aes(x = reorder(canton, positivos), y = positivos)) +
geom_bar(stat = "identity") +
ggtitle("Cantidad de casos positivos de covid-19 por cantón") +
xlab("Cantón") +
ylab("Casos positivos") +
coord_flip() + # se invierten los ejes para generar barras horizontales
theme_minimal()
ggplotly(ggplot2_barras_identity) %>% config(locale = 'es')